package com.cskaoyan.service;

import com.cskaoyan.bean.Admin;
import com.cskaoyan.bean.AdminExample;
import com.cskaoyan.bean.BasePageData;
import com.cskaoyan.bean.BaseParam;
import com.cskaoyan.mapper.AdminMapper;
import com.cskaoyan.util.MarketPageUtil;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AdminServiceImpl implements AdminService{
    @Autowired
    AdminMapper adminMapper;

    @Override
    public BasePageData<Admin> list(String username, BaseParam param) {
        MarketPageUtil.startPage(param);
        AdminExample adminExample = new AdminExample();
        AdminExample.Criteria criteria = adminExample.createCriteria();
        if (username != null && !"".equals(username)) {
            criteria.andUsernameLike("%" + username + "%");
        }
        adminExample.setOrderByClause(param.getSort() + " " + param.getOrder());
        List<Admin> admins = adminMapper.selectByExample(adminExample);

        return BasePageData.ok(admins);
    }
}
